package com.wishu.houses.service.impl;

import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNodeConfig;
import cn.hutool.core.lang.tree.TreeUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wishu.houses.domain.SysRegion;
import com.wishu.houses.service.SysRegionService;
import com.wishu.houses.mapper.SysRegionMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author liu'wen
 * @description 针对表【sys_region(地区表)】的数据库操作Service实现
 * @createDate 2023-04-21 15:36:15
 */
@Service
public class SysRegionServiceImpl extends ServiceImpl<SysRegionMapper, SysRegion>
        implements SysRegionService {

    @Resource
    private SysRegionMapper sysRegionMapper;

    @Override
    public List<Tree<String>> treeRegion() {
        //配置
        TreeNodeConfig treeNodeConfig = new TreeNodeConfig();
        List<SysRegion> sysRegions = sysRegionMapper.selectList(null);
        //转换器
        List<Tree<String>> treeNodes = TreeUtil.build(sysRegions, "0", treeNodeConfig,
                (treeNode, tree) -> {
                    tree.setId(treeNode.getRegionId()+"");
                    tree.setParentId(treeNode.getParentId()+"");
                    tree.setName(treeNode.getRegionName());
                });
        return treeNodes;
    }
}




